package com.base.cn.platform.os.controller.user.integral;

import com.base.cn.platform.os.common.controller.BaseController;
import com.base.cn.platform.os.common.utils.result.ResultUtil;
import com.base.cn.platform.os.entity.user.integral.CusUserIntegral;
import com.base.cn.platform.os.service.user.integral.CusUserIntegralBiz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @Data 用户积分
 * @ClassName  CusUserIntegralController
 * @author :ll
 * @Create Date : 2018年4月24日
 */
@RestController
@RequestMapping("/manage/user")
public class CusUserIntegralController extends BaseController {
    @Autowired
    private CusUserIntegralBiz cusUserIntegralBiz;

    /**
     * 用户ID搜索积分
     * @param userId
     * @return
     */
    @RequestMapping("/queryUserIntegralByUserId")
    public CusUserIntegral queryUserIntegralByUserId(@RequestParam("userId")BigDecimal userId){
        return cusUserIntegralBiz.queryUserIntegralByUserId(userId);
    }

    /**
     * 添加用户积分
     * @param actionKey 动作KEY
     * @param userId 用户ID
     * @param otherId 第三方ID
     * @param score 积分
     * @param recordType 记录类型，1普通记录，2兑换记录
     * @return Map<String,Object>
     */
    @RequestMapping("/addUserIntegral")
    public Map<String,Object> addUserIntegral(@RequestParam(value = "actionKey",required = false) String actionKey,
                                              @RequestParam("userId")BigDecimal userId,
                                              @RequestParam(value = "otherId",required = false,defaultValue = "0")BigDecimal otherId,
                                              @RequestParam(value = "score",required = false,defaultValue = "0") int score,
                                              @RequestParam("recordType") int recordType){
        cusUserIntegralBiz.addUserIntegralData(actionKey,userId,otherId,score,recordType);
        return ResultUtil.SUCCESS("添加用户积分成功");
    }



    /**
     * 添加用户积分注册邀请
     */
    @RequestMapping("/addInvitationUserIntegral")
    public Map<String,Object> addUserIntegral(@RequestParam(value = "inviterKey") String inviterKey,@RequestParam("beInviterId") BigDecimal beInviterId){
        cusUserIntegralBiz.inviterDealWith(inviterKey,beInviterId);
        return ResultUtil.SUCCESS("添加用户积分成功");
    }

    /**
     * 批量添加用户积分
     * @param userIdList 用户id集合
     * @param actionKey 规则key
     */
    @RequestMapping("/batchAddUserIntegral")
    public void  batchAddUserIntegral(@RequestParam("userIdList") List<BigDecimal> userIdList, @RequestParam("actionKey") String actionKey){
        cusUserIntegralBiz.batchAddUserIntegral(userIdList, actionKey);
    }

}
